﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_CM_GetCallinContactBySellmanID]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_CM_GetCallinContactBySellmanID];
GO
CREATE PROCEDURE [dbo].[sproc_CM_GetCallinContactBySellmanID]
@sellmanid int,
@begintime datetime,
@endtime datetime
AS

    SELECT UDS_CM_ClientContact.*,UDS_CM_ClientInfo.name FROM UDS_CM_ClientContact,UDS_CM_ClientInfo
    WHERE MarketmanID=@sellmanid 
    AND UDS_CM_ClientContact.ClientID=UDS_CM_ClientInfo.ID
    AND UDS_CM_ClientContact.ContactTime between @begintime and dateadd(day,1,@endtime)
    AND(patindex('%callin%',UDS_CM_ClientContact.ContactType)>=0
    OR patindex('%interview%',UDS_CM_ClientContact.ContactType)>=0
    OR patindex('%meeting%',UDS_CM_ClientContact.ContactType)>=0)
    ORDER BY UDS_CM_ClientContact.ContactTime desc